package com.qfedu.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class UserController {

    @RequestMapping("test")
    public String test() {
        System.out.println("test进入了");
        return "test";
    }

    @RequestMapping("/show/name")
    public String showName() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        if (principal instanceof User) {
            //认证用户
            User user = (User) principal;
            return user.getUsername();

        }
        //临时用户   未认证
        return principal.toString();

    }
}